<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <!-- <a-button type="primary" @click="handleCreate"> 新增品牌 </a-button> -->
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'payInfo'">
          <Tooltip placement="top">
            <template #title>
              <div>支付单号：12333</div>
              <div>支付时间：2024-01-12 13:12:20</div>
            </template>
            <span class="cursor-pointer flex items-center">
              <Icon v-if="record.status==1" icon="ant-design:alipay-circle-filled" color="#1890ff" size="26" />
              <Icon v-else-if="record.status==0" icon="ant-design:wechat-outlined" color="#009a44" size="26" />
              <span class="ml-2">$ 23.06</span>
            </span>
          </Tooltip>
        </template>
        <template v-else-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                icon: 'ant-design:code-outlined',
                onClick: handleView.bind(null, record),
              },
              {
                icon: 'ant-design:delete-outlined',
                color: 'error',
                popConfirm: {
                  title: '是否确认删除',
                  placement: 'left',
                  confirm: handleDelete.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
    <OrderDrawer @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup>
  import { computed } from 'vue';  
  import { useRoute } from 'vue-router';  
  import { BasicTable, useTable, TableAction } from '@/components/Table';
  import { Tooltip } from 'ant-design-vue';
  import Icon from '@/components/Icon/Icon.vue';
  import { getRoleListByPage } from '@/api/demo/system';

  import { useDrawer } from '@/components/Drawer';
  import OrderDrawer from './OrderDrawer.vue';
  import { columns, searchFormSchema } from './order.data';

// 根据查询参数计算标题  

  defineOptions({ name: 'BrandManagement' });
  const route = useRoute();  

  const payStatus = computed(() => {  
    if(route.name === 'UnPaidOrderManagement') {
      return [0,'未支付订单'];
    }  else if(route.name === 'PaiedOrderManagement') {
      return [1,'已支付订单'];
    } 
    return route.query;
  });  

  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload }] = useTable({
    title: payStatus.value[1],
    api: getRoleListByPage,
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    showIndexColumn: false,
    beforeFetch : (info) => {
      info.payStatus = payStatus.value[0];
      return info;
    },
    actionColumn: {
      width: 80,
      title: '操作',
      dataIndex: 'action',
      // slots: { customRender: 'action' },
    },
  });

  function handleView(record: Recordable) {
    openDrawer(true, {
      record,
      isUpdate: true,
    });
  }

  function handleDelete(record: Recordable) {
    console.log(record);
  }

  function handleSuccess() {
    // reload();
  }
</script>
